package org.example;

// 导入 FFM 模块的相关类
import com.alibaba.fastjson2.JSON;
import org.example.Mouse.CrossPlatformMousePosition;
import org.example.Mouse.MousePoint;
import org.example.dataStorage.Json.JsonStorageConfig;
import org.example.dataStorage.Json.JsonStorageService;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;


public class MainTest {
    /**
     *  获取鼠标位置 并保存
     * @throws InterruptedException  模拟阻塞可能会有中断异常
     */
    @Test
    public void testGetMouseProcessing() throws InterruptedException {
        ArrayList<MousePoint> MousePointList =new ArrayList<>();

        for (int i =0 ; i < 3; i++){
            TimeUnit.SECONDS.sleep(3);//模拟阻塞
            MousePoint position = CrossPlatformMousePosition.getPosition();
            MousePointList.add(position);

            System.out.println("鼠标位置: " + position);
        }

        JsonStorageService jsonStorageService = new JsonStorageService(new JsonStorageConfig());
        jsonStorageService.setJSON(MousePointList);
    }

    /**
     *  设置鼠标位置 并保存
     */
    @Test
    public void testSetMouseProcessing() {
        JsonStorageService jsonStorageService = new JsonStorageService(new JsonStorageConfig());
        String json = jsonStorageService.getJSON();
        List<MousePoint> parse = JSON.parseArray(json, MousePoint.class);
        parse.forEach(e->{

            try {
                Thread.sleep(1200);
            } catch (InterruptedException ex) {
                System.out.println("模拟阻塞可能会有中断异常");
            }

            CrossPlatformMousePosition.setPosition(e.getX(),e.getY());
        });
    }
}